import { Component, Injector } from '@angular/core';
import { BasePage } from '../../../../pages/basePage';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { PIC_URL } from '../../../../providers/Config';
import { StorageService } from '../../../../providers/StorageService';
import { nailerService } from '../../../../providers/nailerService';
/**
 * Generated class for the RefusePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-refuse',
  templateUrl: 'refuse.html',
})
export class RefusePage  extends BasePage{
  picrooturl = ''; //图片服务器的地址
  userinfo = {}//获取内存中的数据
  orderInfo={}   //订单信息
  refuse=[
    {reason:"材料已售完",select:true,selectPic:"assets/img/Comment/diyugeyuandian@2x.png"},
    {reason:"人手不够美甲师放假了",select:false,selectPic:"assets/img/Comment/anniu@2x.png"},
    {reason:"没时间 生意火爆了 爆的不得了啦",select:false,selectPic:"assets/img/Comment/anniu@2x.png"},
    {reason:"放假啦 放假啦 放假啦",select:false,selectPic:"assets/img/Comment/anniu@2x.png"}
  ]
  constructor(injector: Injector,public stc:StorageService,public nailerService:nailerService) {
    super(injector);
    this.picrooturl = PIC_URL;
    this.userinfo = this.stc.read('userinfo');
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad RefusePage');
    this.orderInfo=this.navParams.get("item");
    console.log(this.userinfo);
  }
  dismissCLI(i) {
    this.stc.write("back2",this.navParams.get("par"))
    if(i){
      this.viewCtrl.dismiss(i);
    }else{
      this.viewCtrl.dismiss();
    }
  }
  /**
   * 点击选择该项
   * @param i 选择的某一项
   */
  chose(i){
    this.refuse.forEach((e)=>{
      e.select=false;
      e.selectPic="assets/img/Comment/anniu@2x.png";
    })
    this.refuse[i].select=true;
    this.refuse[i].selectPic="assets/img/Comment/diyugeyuandian@2x.png"
  }
  /**
   * 店主拒绝接单
   */
  async submit(){
    let cancel_reason;
    this.refuse.forEach((e)=>{
      if(e.select){
        cancel_reason=e.reason;
      }
    })
    let param={order_sn:this.orderInfo['order_sn'],shop_id:this.userinfo['shop_id'],cancel_reason:cancel_reason}
    console.log(param);
    let result=await this.nailerService.shopkeeperRefuseOrderAPI(param);
    if(result.code==1){
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 1500,
        position: 'bottom',
      })
      toast.present();
      setTimeout(()=>{
        this.dismissCLI("ok");
      })
    }else{
      let toast = this.toastCtrl.create({
        message: result.msg,
        duration: 1500,
        position: 'bottom',
      })
      toast.present();
    }
  }
}
